home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1613 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  69 lines

  1. Newsgroups: comp.lang.c
  2. Path: in1.uu.net!tellab5!news
  3. From: Joe Toth <toth@tellabs.com>
  4. Subject: Re: Q: realloc->free?
  5. X-Nntp-Posting-Host: sunh25
  6. Content-Type: text/plain; charset=us-ascii
  7. Message-ID: <1996Jan15.205832.2456@tellab5.tellabs.com>
  8. Sender: news@tellab5.tellabs.com (News)
  9. Content-Transfer-Encoding: 7bit
  10. Organization: Tellabs Operations, Inc.
  11. References: <4daa2e$oh5@axe.netdoor.com> <4de8uv$48j@bs33n.staffs.ac.uk>
  12. Mime-Version: 1.0
  13. Date: Mon, 15 Jan 1996 20:58:32 GMT
  14. X-Mailer: Mozilla 1.1 (X11; U; SunOS 4.1.3 sun4c)
  15. X-Url: news:4de8uv$48j@bs33n.staffs.ac.uk
  16.  
  17. cm4bctrd@bs47c.staffs.ac.uk (Wildfire) wrote:
  18. [snip]
  19.  
  20. >realloc() does no free()ing, as far as I know, since the contents of 
  21. >memory are unchanged.
  22.  
  23. The following is an excerpt from the HPUX man page;
  24.  
  25. :    realloc changes the size of the block pointed to by ptr to size bytes
  26. :    and returns a pointer to the (possibly moved) block.  Existing
  27. :    contents are unchanged up to the lesser of the new and old sizes.  If
  28. :    ptr is a NULL pointer, realloc behaves like malloc for the specified
  29. :    size.  If size is zero and ptr is not a NULL pointer, the object it
  30. :    points to is freed and NULL is returned.
  31.                ^^^^^^^^
  32.  
  33. >I would really like someone who properly knows about this to confirm or 
  34. >correct what I'm saying.
  35.  
  36. Test I've done seem to show that there are four situations;
  37.  
  38.   1) the equivalence of the two operations
  39.          a = realloc ( 0, size );
  40.             and
  41.          a = malloc ( size );
  42.   2) the equivalence of the two operations;
  43.          a = realloc ( b, 0 );
  44.             and
  45.          a = free ( b );
  46.   3) the new size can fit such that the pointer doesn't have to change
  47.      and there no free performed.
  48.          a = realloc ( b, size );
  49.      where ( a == b ) = TRUE after the operation. 
  50.   4) the new sized allocation will not fit where the original was and the
  51.      original space is freed and the new space is allocated elsewhere (moved),
  52.      where ( a == b ) = FALSE after the operation
  53.  
  54. Of course, as usual, this is all system dependent.
  55.  
  56. >Wildfire :-)
  57.  
  58. Hope this helps.
  59.  
  60.   _  _  ___  --------------------------+---------------------------------
  61.   | / _  |    Joseph G. Toth Jr.       | Tellabs Operations, Inc.  
  62. \_| \_/  |                             | toth@tellabs.com
  63.  
  64. > Every program has at least one bug and can be shortened by at least
  65. > one instruction -- from which, by induction, it is evident that every
  66. > program can be reduced to one instruction that does not work.
  67. >                       -- Ken Arnold
  68.  
  69.